package com.genntii.examManager.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.genntii.examManager.domain.entity.Exam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

@Mapper
public interface ExamMapper extends BaseMapper<Exam> {

    @Select("select count(*) from exam where course_id = #{courseId}")
    Integer getExamCount(@Param("courseId") Long courseId);

    @Select("select * " +
            "from exam " +
            "where course_id = #{courseId} "+
            "order by update_time DESC " +
            "limit #{pageNum},#{pageSize}")
    ArrayList<Exam> getExamList(@Param("pageNum") Integer pageNum,
                                @Param("pageSize") Integer pageSize,
                                @Param("courseId") Long courseId);

    @Select("select count(*) from exam")
    long getExamTotal();

    ArrayList<Exam> getExamBatch(ArrayList<Long> examIds);

    @Update("update exam set status = #{status} where id = #{courseId}")
    void updateStatus(@Param("status") Byte Status,
                      @Param("courseId") Long courseId);

    @Update("update exam set is_final_exam = 0 where course_id = #{courseId};")
    void setFinalExam(@Param("courseId") Long courseId);

    @Select("select * from exam where course_id = #{courseId}")
    ArrayList<Exam> getExamAllListByCourse(@Param("courseId") Long courseId);

}
